{extend name="$base" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/product.css">
<style type="text/css">
.table-class tbody td a{margin-left: 8px;}
</style>
{/block}
{block name="main"}
<div class="options-btn">
	<button class="btn-common-delete" onclick="batchDelete()">批量删除</button>
	<button class="btn-common" onclick="location.href='{:__URL('ADMIN_MAIN/cms/addtopic')}';">添加专题</button>
</div>
<table class="table-class">
	<colgroup>
		<col style="width: 2%">
<!-- 	<col style="width: 5%;"> -->
		<col style="width: 61%;">
		<col style="width: 7%;">
		<col style="width: 15%;">
		<col style="width: 15%">
	</colgroup>
	<thead>
		<tr align="center">
			<th><i class="checkbox-common" input_all =".table-class tbody">
			<input id="ckall" type="checkbox" ></i></th>
			<!-- <th>排序</th> -->
			<th align="left">标题</th>
			<th>状态</th>
			<th>发布时间</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody></tbody>
</table>
{/block}
{block name="script"}
<script type="text/javascript">
function LoadingInfo(page_index) {
	var search_text = $("#search_text").val();
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/cms/topiclist')}",
		data : {
			"page_index" : page_index, "page_size" : $("#showNumber").val(), "search_text" : search_text
		},
		success : function(data) {
			if (data["data"].length > 0) {
				$(".table-class tbody").empty();
				for (var i = 0; i < data["data"].length; i++) {
					var html = '';
					html += '<tr align="center">';
					html += '<td><i class="checkbox-common"><input name="sub" type="checkbox" value="'+ data['data'][i]['topic_id']+'" ></i></td>';
// 					html += '<td><input type="number" min="0" value="'+ data["data"][i]["topic_id"]+'"  fieldid="'+ data['data'][i]['topic_id']+'" class="num" ></td>';
					html += '<td  align="left" class="tal" title="'+data["data"][i]["title"]+'">' + data["data"][i]["title"]+ '</td>';
					if(data["data"][i]["status"]==0){
						html += '<td>未发布</td>';
					}else{
						html += '<td>已发布</td>';
					}
					html += '<td>' + timeStampTurnTime(data["data"][i]["create_time"])+ '</td>';
					html += '<td><a target="_blank" href="'+__URL('SHOP_MAIN/topic/detail?topic_id='+ data['data'][i]['topic_id'])+'">预览</a><a href="'+__URL('ADMIN_MAIN/cms/updatetopic?id='+ data['data'][i]['topic_id'])+'">修改</a><a style="cursor: pointer;" onclick="deleteTopic('+data['data'][i]['topic_id']+')">删除</a></td> ';
					html += '</tr>';
					$(".table-class tbody").append(html);
				}
			} else {
				var html = '<tr align="center"><td colspan="9">暂无专题</td></tr>';
				$(".table-class tbody").html(html);
			}
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
			load();
		}
	});
}	

function batchDelete() {
	var topic_id= new Array();
	$(".table-class tbody input[type='checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			topic_id.push($(this).val());
		}
	});
	if(topic_id.length ==0){
		$( "#dialog" ).dialog({
			buttons: {
				"确定,#0059d6,#fff": function() {
					$(this).dialog('close');
				}
			},
			contentText:"请选择需要操作的记录",
			title:"消息提醒",
		});
		return false;
	}
	deleteTopic(topic_id);
}
var flag = false;
//删除
function deleteTopic(topic_id){
	$( "#dialog" ).dialog({
		buttons: {
			"确定": function() {
				$(this).dialog('close');
				if(!flag){
					flag = true;
					$.ajax({
						type : "post",
						url : "{:__URL('ADMIN_MAIN/cms/deletetopic')}",
						data : {
							"topic_id" : topic_id.toString()
						},
						dataType : "json",
						success : function(data) {
							if (data["code"] > 0) {
								showTip(data["message"],'success');
								LoadingInfo(getCurrentIndex(topic_id,'.table-class tbody'));
							}else{
								showTip(data["message"],'error');
								flag = false;
							}
						}
					})
				}
			},
			"取消,#f5f5f5,#666": function() {
				$(this).dialog('close');
			}
		},
	contentText:"是否删除专题？",
	});
}

/*修改排序*/
function load(){
	$('.num').change(function(){
		var fieldid = $(this).attr('fieldid');
		var sort = $(this).val();
		$.ajax({
			type:"post",
			url:"{:__URL('ADMIN_MAIN/cms/modifyarticlefield')}",
			data:{'fieldid':fieldid,'sort':sort},
			success: function (data) {
				if(data['code'] > 0){
					showTip(data["message"],'success');
				}else{
					showTip(data["message"],'error');
				}
			}
		});
	});
}

</script>
{/block}